package com.itheima.factory;

import com.itheima.controller.IStudentController;
import com.itheima.controller.ITeacherController;
import com.itheima.controller.impl.StudentControllerImpl;
import com.itheima.controller.impl.TeacherControllerImpl;
import com.itheima.dao.IStudentDao;
import com.itheima.dao.impl.StudentDaoImpl;
import com.itheima.service.IStudentService;
import com.itheima.service.impl.StudentServiceImpl;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

/*
工厂类
用来生产对象
 */
public class Factory {

    public static Properties prop= new Properties();
    static {
        try {
          prop.load(new FileInputStream("zhongjiban\\peizhi\\beans.properties"));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


    public static IStudentController getStudentController() {
        String iStudentController = prop.getProperty("IStudentController");
        System.out.println(iStudentController);
        Class<IStudentController> clazz=null;
        IStudentController studentController=null;
        try {
            clazz = (Class<IStudentController>) Class.forName(iStudentController);
             studentController = clazz.newInstance();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        }

        return studentController;
    }

    public static ITeacherController getTeacherController()
    {
        return new TeacherControllerImpl();
    }

    public static IStudentService getStudentService()
    {
        String IStudentService = prop.getProperty("IStudentService");
        System.out.println(IStudentService);
        return new StudentServiceImpl();
    }

    public static IStudentDao getStudentDao()
    {
        String IStudentDao = prop.getProperty("IStudentDao");
        System.out.println(IStudentDao);
        return new StudentDaoImpl();
    }
}
